from typing import Optional
from sqlalchemy.orm import Session
from mooc.crud.crud_base import CRUDBase

from mooc.models.goouc_fullexam import (Advert, Banji, Banner, Category, Cdkey, CdkeyCate, Cdkeys, Exercise, Feedback,
                                        Gift, IndexBtn, Knowledge, KnowledgeCate, Notice, Order, Paper, PaperTest,
                                        Phonecode, QYear, School, Setting, ShareRecord, SonSimple, Test, TestType,
                                        TypeCate, Watermark, Wxtpl, Xuesheng
                                        )
from mooc.schemas.goouc_fullexam import (AdvertUpdate, AdvertCreate, BanjiUpdate, BanjiCreate, BannerCreate,
                                         BannerUpdate, CategoryCreate, CategoryUpdate, CdkeyCreate, CdkeyUpdate,
                                         CdkeyCateCreate, CdkeyCateUpdate, IndexBtnCreate, IndexBtnUpdate, GiftCreate,
                                         GiftUpdate, CdkeysCreate, CdkeysUpdate, ExerciseCreate, ExerciseUpdate,
                                         FeedbackCreate, FeedbackUpdate, TypeCateCreate, TypeCateUpdate,
                                         KnowledgeCreate, KnowledgeUpdate, KnowledgeCateCreate, KnowledgeCateUpdate,
                                         NoticeCreate, NoticeUpdate, OrderCreate, OrderUpdate, PaperCreate, PaperUpdate,
                                         PaperTestCreate, PaperTestUpdate, PhoneCodeUpdate, PhoneCodeCreate,
                                         QYearCreate, QYearUpdate, SchoolCreate, SchoolUpdate, SettingCreate,
                                         SettingUpdate, ShareRecordCreate, ShareRecordUpdate, SonSimpleCreate,
                                         SonSimpleUpdate, TestCreate, TestUpdate, TestTypeCreate, TestTypeUpdate,
                                         WatermarkCreate, WatermarkUpdate, WxTplCreate, WxTplUpdate,
                                         XueshengCreate, XueshengUpdate
                                         )


class CRUDAdvert(CRUDBase[Advert, AdvertCreate, AdvertUpdate]):
    def get_advert(self, db: Session, admin_id: int) -> Optional[Advert]:
        return self.get_by_field(db, "id", admin_id)


class CRUDBanji(CRUDBase[Banji, BanjiCreate, BanjiUpdate]):
    def get_banji(self, db: Session, banji_id: int) -> Optional[Banji]:
        return self.get_by_field(db, "banji_id", banji_id)


class CRUDBanner(CRUDBase[Banner, BannerCreate, BannerUpdate]):
    def get_banner(self, db: Session, banner_id: int):
        return self.get_by_field(db, "id", banner_id)


class CRUDCategory(CRUDBase[Category, CategoryCreate, CategoryUpdate]):
    def get_category(self, db: Session, category_id: int):
        return self.get_by_field(db, "id", category_id)


class CRUDCdkey(CRUDBase[Cdkey, CdkeyCreate, CdkeyUpdate]):
    def get_cdkey(self, db: Session, cdkey_id: int):
        return self.get_by_field(db, "id", cdkey_id)


class CRUDCdkeyCate(CRUDBase[CdkeyCate, CdkeyCateCreate, CdkeyCateUpdate]):
    def get_cdkey_cate(self, db: Session, cdkey_cate_id: int):
        return self.get_by_field(db, "id", cdkey_cate_id)


class CRUDCdkeys(CRUDBase[Cdkeys, CdkeysCreate, CdkeysUpdate]):
    def get_cdkeys(self, db: Session, cdkeys_id: int):
        return self.get_by_field(db, "id", cdkeys_id)


class CRUDExercise(CRUDBase[Exercise, ExerciseCreate, ExerciseUpdate]):
    def get_exercise(self, db: Session, exercise_id: int):
        return self.get_by_field(db, "id", exercise_id)


class CRUDFeedback(CRUDBase[Feedback, FeedbackCreate, FeedbackUpdate]):
    def get_feedback(self, db: Session, feedback_id: int):
        return self.get_by_field(db, "id", feedback_id)


class CRUDGift(CRUDBase[Gift, GiftCreate, GiftUpdate]):
    def get_gift(self, db: Session, gift_id: int):
        return self.get_by_field(db, "id", gift_id)


class CRUDIndexBtn(CRUDBase[IndexBtn, IndexBtnCreate, IndexBtnUpdate]):
    def get_index_btn(self, db: Session, index_btn_id: int):
        return self.get_by_field(db, "id", index_btn_id)


class CRUDKnowledge(CRUDBase[Knowledge, KnowledgeCreate, KnowledgeUpdate]):
    def get_knowledge(self, db: Session, knowledge_id: int):
        return self.get_by_field(db, "knowledge_id", knowledge_id)


class CRUDKnowledgeCate(CRUDBase[KnowledgeCate, KnowledgeCateCreate, KnowledgeCateUpdate]):
    def get_knowledge_cate(self, db: Session, knowledge_cate_id: int):
        return self.get_by_field(db, "id", knowledge_cate_id)


class CRUDNotice(CRUDBase[Notice, NoticeCreate, NoticeUpdate]):
    def get_notice(self, db: Session, notice_id: int):
        return self.get_by_field(db, "id", notice_id)


class CRUDOrder(CRUDBase[Order, OrderCreate, OrderUpdate]):
    def get_order(self, db: Session, order_id: int):
        return self.get_by_field(db, "id", order_id)


class CRUDPaper(CRUDBase[Paper, PaperCreate, PaperUpdate]):
    def get_paper(self, db: Session, paper_id: int):
        return self.get_by_field(db, "id", paper_id)


class CRUDPaperTest(CRUDBase[PaperTest, PaperTestCreate, PaperTestUpdate]):
    def get_paper_test(self, db: Session, paper_test_id: int):
        return self.get_by_field(db, "id", paper_test_id)


class CRUDPhonecode(CRUDBase[Phonecode, PhoneCodeCreate, PhoneCodeUpdate]):
    def get_phonecode(self, db: Session, phonecode_id: int):
        return self.get_by_field(db, "id", phonecode_id)


class CRUDQYear(CRUDBase[QYear, QYearCreate, QYearUpdate]):
    def get_qyear(self, db: Session, qyear_id: int):
        return self.get_by_field(db, "id", qyear_id)


class CRUDSchool(CRUDBase[School, SchoolCreate, SchoolUpdate]):
    def get_school(self, db: Session, school_id: int):
        return self.get_by_field(db, "school_id", school_id)


class CRUDSetting(CRUDBase[Setting, SettingCreate, SettingUpdate]):
    def get_setting(self, db: Session, setting_id: int):
        return self.get_by_field(db, "id", setting_id)


class CRUDShareRecord(CRUDBase[ShareRecord, ShareRecordCreate, ShareRecordUpdate]):
    def get_share_record(self, db: Session, share_record_id: int):
        return self.get_by_field(db, "id", share_record_id)


class CRUDsonSimple(CRUDBase[SonSimple, SonSimpleCreate, SonSimpleUpdate]):
    def get_son_simple(self, db: Session, son_simple_id: int):
        return self.get_by_field(db, "id", son_simple_id)


class CRUDTest(CRUDBase[Test, TestCreate, TestUpdate]):
    def get_test(self, db: Session, test_id: int):
        return self.get_by_field(db, "test_id", test_id)


class CRUDTestType(CRUDBase[TestType, TestTypeCreate, TestTypeUpdate]):
    def get_test_type(self, db: Session, test_type_id: int):
        return self.get_by_field(db, "id", test_type_id)


class CRUDTypeCate(CRUDBase[TypeCate, TypeCateCreate, TypeCateUpdate]):
    def get_type_cate(self, db: Session, type_cate_id: int):
        return self.get_by_field(db, "id", type_cate_id)


class CRUDWatermark(CRUDBase[Watermark, WatermarkCreate, WatermarkUpdate]):
    def get_watermark(self, db: Session, watermark_id: int):
        return self.get_by_field(db, "id", watermark_id)


class CRUDWxTpl(CRUDBase[Wxtpl, WxTplCreate, WxTplUpdate]):
    def get_wx_tpl(self, db: Session, wx_tpl_id: int):
        return self.get_by_field(db, "id", wx_tpl_id)


class CRUDXueshen(CRUDBase[Xuesheng, XueshengCreate, XueshengUpdate]):
    def get_xueshen(self, db: Session, xueshen_id: int):
        return self.get_by_field(db, "xuesheng_id", xueshen_id)


advert = CRUDAdvert(Advert)
banji = CRUDBase(Banji)
banner = CRUDBanner(Banner)
category = CRUDCategory(Category)
cdkey = CRUDCdkey(Cdkey)
cdkey_cate = CRUDCdkeyCate(CdkeyCate)
cdkeys = CRUDCdkeys(Cdkeys)
exercise = CRUDExercise(Exercise)
feedback = CRUDFeedback(Feedback)
gift = CRUDGift(Gift)
index_btn = CRUDIndexBtn(IndexBtn)
knowledge = CRUDKnowledge(Knowledge)
knowledge_cate = CRUDKnowledgeCate(KnowledgeCate)
notice = CRUDNotice(Notice)
order = CRUDOrder(Order)
paper = CRUDPaper(Paper)
paper_test = CRUDPaperTest(PaperTest)
phone_code = CRUDPhonecode(Phonecode)
q_year = CRUDSchool(School)
school = CRUDSchool(School)
setting = CRUDSetting(Setting)
share_record = CRUDShareRecord(ShareRecord)
son_simple = CRUDsonSimple(SonSimple)
test = CRUDTest(Test)
test_type = CRUDTestType(TestType)
type_cate = CRUDTypeCate(TypeCate)
watermark = CRUDWatermark(Watermark)
wx_tpl = CRUDWxTpl(Wxtpl)
xueshen = CRUDXueshen(Xuesheng)
